package org.example.springioc;

import org.example.springioc.Component.UserComponent;
import org.example.springioc.DI.Controller1;
import org.example.springioc.DI.Controller2;
import org.example.springioc.DI.Controller3;
import org.example.springioc.DI.Controller4;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;


//如果不添加扫描机制，那么只会从自己所在包下查找
//@ComponentScan({"org.example.springioc"})
//如果想要访问替他的可以使用@ReflectiveScan
//启动类

@ComponentScan(basePackages = {"org.example.springioc"})
@SpringBootApplication//注解内部包含了扫描地址@ReflectiveScan的操作
public class SpringIocApplication {

    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(SpringIocApplication.class, args);
/*        Hello bean = context.getBean(Hello.class);
        bean.say();*/

/*//        been的常见用法,这三种方法获取的资源都是同一个
//        1.使用名称获取
        Hello hello = (Hello)context.getBean("hello");
        System.out.println(hello);

//        2. 使用类获取
        Hello hello1 = context.getBean(Hello.class);
        System.out.println(hello1);

//        3. 使用名称+类
        Hello hello2 = context.getBean("hello", Hello.class);
        System.out.println(hello2);

//        been的名称获取参照java获取，如果是连续的两个大写字母，则第一个不用小写，正常的情况大写字母都需要小写;
        System.out.println(Introspector.decapitalize("Hello"));
        System.out.println(Introspector.decapitalize("HHello"));*/

/*//        测试
        UserComponent bean1 = context.getBean(UserComponent.class);
        bean1.doComponent();
        UserConfig bean2 = context.getBean(UserConfig.class);
        bean2.doConfig();
        UserRepository bean3 = context.getBean(UserRepository.class);
        bean3.doRepo();
        UserService bean4 = context.getBean(UserService.class);
        bean4.doService();*/



//        @bean学习
/*        报错，存在多个，不是唯一
        People bean = context.getBean(People.class);
        System.out.println(bean);*/

/*//        正常使用
        Object p = context.getBean("p");
        System.out.println(p);
        Object p1 = context.getBean("p1");
        System.out.println(p1);*/

//        DI测试
        //方法1测试
        Controller1 bean = context.getBean(Controller1.class);
        bean.say();
        //方法2测试
        Controller2 bean1 = context.getBean(Controller2.class);
        bean1.say();
        //方法3测试
        Controller3 bean2 = context.getBean(Controller3.class);
        bean2.say();

        //方法4测试
        Controller4 bean3 = context.getBean(Controller4.class);
        bean3.say();
    }



}
